﻿using System;

namespace GGFramework.Core.Timer
{
    public class CountdownTimer : TimerBase
    {
        public CountdownTimer() : base(0) { }

        public virtual void Init(float duration)
        {
            Duration = duration;
            RemainingTime = duration;
        }

        public override void Update(float deltaTime)
        {
            base.Update(deltaTime);

            if (RemainingTime <= 0)
            {
                Complete();
                IsCompleted = true;
            }
        }

        public override bool IsExpired => RemainingTime <= 0;
        
        public override void Cancel()
        {
            IsCompleted = true;
        }
    }
}